package org.ranshiyan.config;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
@Component
@Slf4j
public class AopPoint {

    @Pointcut("@annotation(org.springframework.web.bind.annotation.GetMapping)")
    private void logAdvicePointcut() {

    }

    @Before("logAdvicePointcut()")
    public void logAdviceBefore(JoinPoint joinPoint){
        // 这里只是一个示例，你可以写任何处理逻辑
        Signature signature = joinPoint.getSignature();
        log.info("方法名称"+signature.getName()+"参数为"+ Arrays.toString(joinPoint.getArgs()));
    }

    @After("logAdvicePointcut()")
    public void logAdviceAfter(JoinPoint joinPoint){
        Signature signature = joinPoint.getSignature();
        log.info("返回值"+signature.getDeclaringTypeName());
    }
}
